<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\Trade
 *
 * @property int $trade_id
 * @property int $payer_uid 付款方ID
 * @property string|null $payer_name 付款方账号
 * @property int $payee_uid 收款方ID
 * @property string|null $payee_name 收款方账户
 * @property string|null $pay_type 支付方式
 * @property int $pay_status 支付状态,0=未支付，1=已支付
 * @property string|null $pay_at
 * @property string $trade_no 交易号
 * @property string|null $subject 交易名称
 * @property string|null $body 交易描述
 * @property float $total_amount 交易金额
 * @property string|null $trade_type 交易类型
 * @property int $trade_status
 * @property string $created_at 交易时间
 * @property string $updated_at
 * @property string|null $out_trade_no 第三方支付订单号
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereBody($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereOutTradeNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayeeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayeeUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayerName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade wherePayerUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereSubject($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereTotalAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereTradeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereTradeNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereTradeStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereTradeType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Trade whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property-read \App\Models\Order $order
 * @property-read \App\Models\User $payee
 * @property-read \App\Models\User $payer
 */
class Trade extends Model
{
    protected $table = 'trade';
    protected $primaryKey = 'trade_id';
    protected $guarded = ['trade_id'];
    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            $model->created_at = time();
            $model->updated_at = time();
        });

        static::updating(function ($model){
            $model->updated_at = time();
        });
    }

    /**
     * 付款方
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function payer()
    {
        return $this->belongsTo(User::class, 'payer_uid', 'uid');
    }

    /**
     * 收款方
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function payee()
    {
        return $this->belongsTo(User::class, 'payee_uid', 'uid');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function order()
    {
        return $this->belongsTo(Order::class, 'trade_no', 'trade_no');
    }
}
